00001
00002 Audio::Audio()
00003 {
00004 context_id = NULL;
00005 }
00006
00007 int Audio::initSound()
00008 {
00009 static void *wave = NULL;
00010 ALsizei size;
00011 ALsizei freq;
00012 ALenum format;
00013 ALboolean loop;
00014 int attrlist[] = { ALC_FREQUENCY, 44100, 0 };
00015 dev = alcOpenDevice( NULL );
00016 if( dev == NULL ) {
00017 return 1;
00018 }
00019 context_id = alcCreateContext( dev, attrlist);
00020 if(context_id == NULL) {
00021 alcCloseDevice( dev );
00022 return 1;
00023 }
00024
00025 alcMakeContextCurrent( context_id );
00026
00027 alDistanceModel(AL_INVERSE_DISTANCE);
00028
00029 ALfloat weirdpos[] = { 0.0f, 0.0f, 0.0f };
00030
00031 alListenerfv( AL_POSITION, weirdpos );
00032 alGenBuffers( 2, boom );
00033
00034 if(alGetError() != AL_NO_ERROR)
00035 return AL_FALSE;
00036
00037 alutLoadWAVFile("Data/audio/passenger.wav", &format, &data,&size, &freq,&loop);
00038
00039 alBufferData( boom[0], format, data,size, freq );
00040
00041 alutUnloadWAV(format,data,size,freq);
00042
00043
00044 alutLoadWAVFile("Data/audio/car_crash.wav", &format, &data,&size, &freq,&loop);
00045
00046 alBufferData( boom[1], format, data,size, freq );
00047
00048 alutUnloadWAV(format,data,size,freq);
00049
00050 alGenSources( 2, moving_source);
00051
00052 sound_id=moving_source[0];
00053
00054 alSourcei( moving_source[0], AL_BUFFER, boom[0] );
00055 alSourcei( moving_source[0], AL_LOOPING, AL_TRUE );
00056 alSourcei( moving_source[0], AL_SOURCE_RELATIVE, AL_TRUE );
00057 alSourcef( moving_source[0], AL_PITCH, 1.00 );
00058 alSourcef( moving_source[0], AL_REFERENCE_DISTANCE, 0.30f);
00059 alSourcef( moving_source[0], AL_ROLLOFF_FACTOR, 0.3f);
00060 alSourcef( moving_source[0], AL_MAX_GAIN, 0.03f);
00061 alSourcef( moving_source[0], AL_MIN_GAIN, 0.0f);
00062
00063 sound_crash_id = moving_source[1];
00064 alSourcei( moving_source[1], AL_BUFFER, boom[1] );
00065 alSourcei( moving_source[1], AL_LOOPING, AL_FALSE );
00066 alSourcei( moving_source[1], AL_SOURCE_RELATIVE, AL_TRUE );
00067 alSourcef( moving_source[1], AL_PITCH, 1.00 );
00068 alSourcef( moving_source[1], AL_REFERENCE_DISTANCE, 10.0f);
00069 alSourcef( moving_source[1], AL_ROLLOFF_FACTOR, 1.0f);
00070 alSourcef( moving_source[1], AL_MAX_GAIN, 1.0f);
00071 alSourcef( moving_source[1], AL_MIN_GAIN, 0.0f);
00072
00073 }
00074
00075
00076 void Audio::exitOpenAL()
00077 {
00078 ALCcontext* pCurContext;
00079 ALCdevice* pCurDevice;
00080 pCurContext = alcGetCurrentContext();
00081 pCurDevice = alcGetContextsDevice(pCurContext);
00082 alcMakeContextCurrent(NULL);
00083 alcDestroyContext(pCurContext);
00084 alcCloseDevice(pCurDevice);
00085 }
00086
00087 void Audio::killALData()
00088 {
00089 alDeleteBuffers(2, boom);
00090 alDeleteSources(1, moving_source);
00091 alutExit();
00092
00093 }
00094
00095 int Audio::getSoundId()
00096 {
00097 return sound_id;
00098 }
00099
00100 int Audio::getSoundCrashId()
00101 {
00102 return sound_crash_id;
00103 }